﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ExpressionTreeLib;

namespace EditorExe.StepRequestDialogs
{
    /// <summary>
    /// Interaction logic for RequestClrType.xaml
    /// </summary>
    public partial class RequestClrType : Window, IStepRequest<Type>
    {
        public RequestClrType()
        {
            InitializeComponent();
        }

        public bool Request(ref Type input)
        {
            this.button1.Content = "Next";
            return this.LastRequest(ref input);
        }

        public bool LastRequest(ref Type input)
        {
            this.textBox1.Text = input.FullName;
            if (this.ShowDialog() ?? false)
            {
                input = Type.GetType(this.textBox1.Text);
                return true;
            }

            return false;
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Type.GetType(this.textBox1.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Fail to load type.\n" + ex.Message);
            }
            this.DialogResult = true;
            this.Close();
        }
    }
}
